-- log_by_lua 阶段,处理 cls_lua_waf 日志

local log_tbl = ngx.ctx.cls_lua_waf_log
if log_tbl == nil or type(log_tbl) ~= "table" then
    return
end

local log_str = table.concat(log_tbl, "\n")

-- 重新打开waf日志文件
if not g_log_file_handle then
    g_log_file_handle = io.open(g_config.waf_log_file, "a")
    if not g_log_file_handle then
        ngx.log(ngx.ERR, ' cls_lua_waf log file open failed at log parse.')
        return
    end
end

-- ngx.log(ngx.ALERT, 'waf日志记录:'..log_str)

g_log_file_handle:write(log_str..'\n')
g_log_file_handle:flush()

-- g_log_file_handle:close()

